package proyecto.DataAccessObject;

import java.util.List;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import proyecto.EntityBeans.VinculacionAlumno;

@Stateless
@Remote(VinculacionAlumnoDAORemote.class)
public class VinculacionAlumnoDAO implements VinculacionAlumnoDAORemote{

	@PersistenceContext
	EntityManager entityManager;


	public int save (VinculacionAlumno vinculacionAlumno){		
		try{			
			entityManager.persist(vinculacionAlumno);			
		} 
		catch(Exception e){
			e.printStackTrace();
		}
		
		return vinculacionAlumno.getIdVA();
	}
	

	public VinculacionAlumno findByIdVA(int id) {
		return entityManager.find(VinculacionAlumno.class, id);
		
	}
	
		
	public void merge(VinculacionAlumno vinculacionAlumno) {
		try{						
			entityManager.merge(vinculacionAlumno);
		} 
		catch(Exception e){
			e.printStackTrace();
		}
	}
			
	public List findAll() {		
		return entityManager.createQuery("from VinculacionAlumno").getResultList();
	}
	
	public List findByid(int idVinculacion, int idAlumno) {		
		return entityManager.createQuery("select v from VinculacionAlumno v where v.vinculacion.idVinculacion = :idVinculacion and v.alumno.idAlumno = :idAlumno").setParameter("idVinculacion", idVinculacion).setParameter("idAlumno", idAlumno).getResultList();
	}
		
	public void remove(int idVinculacionAlumno){	
		entityManager.remove(entityManager.find(VinculacionAlumno.class, idVinculacionAlumno));
	}
}
